package com.briup.srms.sms.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.srms.sms.bean.ClazzRoom;
import com.briup.srms.sms.service.IClazzRoomService;
import com.jacky.base.utils.Message;
import com.jacky.base.utils.MessageUtil;
import com.jacky.base.utils.PageVM;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @program: 杰普基础管理系统
 * @description: 教室控制器类
 * @author: charles
 * @create: 2020-12-27 17:22
 **/
@Api(description = "教室相关接口")
@Validated
@RestController
@RequestMapping("/clazz_room")
public class ClazzRoomController {

	@Autowired
	private IClazzRoomService clazzRoomService;

	@ApiOperation(value = "分页多条件获取教室信息")
	@GetMapping("pageQuery")
	@ApiImplicitParams({ @ApiImplicitParam(name = "page", value = "当前页", required = true, paramType = "query"),
			@ApiImplicitParam(name = "pageSize", value = "每页大小", required = true, paramType = "query"), })
	public Message pageQuery(int page, int pageSize) {
		PageVM<ClazzRoom> pageVM = clazzRoomService.pageQuery(page, pageSize);
		return MessageUtil.success(pageVM);
	}


	@ApiOperation(value = "通过id删除")
	@ApiImplicitParams(@ApiImplicitParam(name = "id", value = "主键", paramType = "query", required = true))
	@GetMapping("deleteById")
	public Message deleteById(long id) {
		clazzRoomService.deleteById(id);
		return MessageUtil.success("删除成功");
	}

	@ApiOperation(value = "保存或更新消息信息", notes = "如果参数中包含id后端认为是更新操作，如果参数中不包含id认为是插入操作")
	@PostMapping("saveOrUpdate")
	public Message saveOrUpdate(ClazzRoom clazzRoom) {
		clazzRoomService.saveOrUpdate(clazzRoom);
		return MessageUtil.success("更新成功");
	}
}
